package  com.zkingsoft.services.impl;

import  com.zkingsoft.services.ChangesService;
import com.zkingsoft.plugin.pojo.PaginationVO;
import com.zkingsoft.plugin.util.WebUtil;
import  com.zkingsoft.model.Changes;
import com.zkingsoft.model.Task;
import com.zkingsoft.constance.Dictionary;
import  com.zkingsoft.dao.ChangesDao;
import com.zkingsoft.dao.TaskDao;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2016-11-15 11:54
 */
@Service("changesService")
public class  ChangesServiceImpl implements    ChangesService  {

	
	@Autowired
	private ChangesDao changesDao;
	@Autowired
	private TaskDao taskDao;
	
	
	@Override
	public int add(Changes changes){
		
		return changesDao.insert(changes);
		
	}
   	
	@Transactional
    @Override
	public int modify(Changes changes){
		if(changes.getStrUserId()!= null){
			changes.setTaskStatus(Dictionary.TASK_STATUS_YCJ);
			Task task=new Task();
			task.setProjId(changes.getProjId());
			task.setCateId(changes.getInterfaceId());
			task.setName(changes.getTitle());
			task.setUserId(changes.getStrUserId());
			task.setCreateUserId(changes.getOptionUserId());
			task.setCreateTime(new Date());
			task.setEndTime(changes.getEndTime());
			
			String des=changes.getContent();
	   		String url=WebUtil.getRequest().getScheme() + "://" + WebUtil.getRequest().getServerName() + ":" + WebUtil.getRequest().getServerPort()
	   				+WebUtil.getRequest().getContextPath()+"/admin/changes/showForm?id="+changes.getId();
	   		des+="【任务来源，<a target='blank' href='"+url+"'>请点击链接查看</a>】";
	   		task.setDescribes(des);
			task.setRemark(changes.getRemark());
			task.setTaskType(Dictionary.TASK_TYPE_EDVELOP);
			task.setStatus(Dictionary.TASK_STATUS_NO_START);
			task.setLevel(changes.getLevel());
			task.setGoldNum(changes.getGoldNum());
			task.setExperienceNum(changes.getExperienceNum());
			task.setChangesId(changes.getId());
			task.setIsdel(Dictionary.IS_N);
			task.setOvertime(0L);
			taskDao.insert(task);
			}
		
		
		return changesDao.update(changes);
	
	}
	
	@Override
	public int remove(List<Long> list){
	
		return changesDao.deleteByIds(list);
	
	}

	@Override
	public int removeById(Long id){
	
		return changesDao.deleteById(id);
	
	}
	
	@Override
	public int removeByModel(Changes changes){
	
		return changesDao.deleteByModel(changes);
	
	}
	
	
	@Override
	public List<Changes> findInPage(Changes changes,  PaginationVO pageVo){
	
		return changesDao.selectInPage(changes , pageVo);
	
	}
	
	@Override
	public List<Changes> findByModel(Changes changes){
	
		return changesDao.selectByModel(changes);
	
	}
	
	@Override
	public int  findTotal(Changes changes){
	
		return changesDao.selectTotalRecord(changes);
	
	}
	
	@Override
	public Changes  findById(Long id){
	
		return changesDao.selectById(id);
	
	}

	@Override
	public Changes findUserCodeByChangesId(Long id) {
		
		return changesDao.selectUserCodeByChangesId(id);
	}

   	
	
	
}